package com.gemalto.Kryptik.Gui;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.*;
import java.util.Vector;
import com.gemalto.Kryptik.Util.*;
import com.gemalto.Kryptik.Algo.*;
import com.gemalto.Kryptik.*;

public class MACAlgoTab extends JPanel implements AlgoTab, ListSelectionListener {

	private JPanel leftPanel, rightPanel,  buttonPanel;
	private AlgoPanel algoPanel;
	private JButton okButton, cancelButton;
	private JList keyList;
	private AlgoManager algoManager;

	public MACAlgoTab(IniFiles ini, AlgoManager algoManager){
		super();	
		algoManager.registerGui(this);
		this.algoManager=algoManager;	

		setLayout(new BoxLayout(this, 0));
		leftPanel = new JPanel();
		rightPanel = new JPanel();
		
		leftPanel.setLayout(new BoxLayout(leftPanel, 1));
		JLabel listLabel = new JLabel(ini.getValue("TRANSLATION","MACALGO_ALGO_LABEL"));
		listLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
		leftPanel.add(listLabel);
//		leftPanel.setBorder(BorderFactory.createTitledBorder(ini.getValue("TRANSLATION","ALGO_ALGO_LABEL")));		
		algoPanel=new DummyAlgoPanel();
	
		keyList = new JList(algoManager.getStore());
		keyList.addListSelectionListener(this);
		//keyList.setSelectedIndex(0);
		JScrollPane listScrollPane = new JScrollPane(keyList);
		listScrollPane.setAlignmentX(Component.LEFT_ALIGNMENT);
		listScrollPane.setMaximumSize(new Dimension(100, Short.MAX_VALUE));
		listScrollPane.setPreferredSize(new Dimension(100, 150));
		listScrollPane.setMinimumSize(new Dimension(100, 100));
		keyList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		leftPanel.add(listScrollPane);	
		
		rightPanel.setLayout(new BoxLayout(rightPanel, 1));
		rightPanel.setBorder( //new javax.swing.border.CompoundBorder(
					new javax.swing.border.EmptyBorder(2,2,0,0)//,
					//new javax.swing.border.EtchedBorder())
				    );
		rightPanel.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
		rightPanel.setMinimumSize(new Dimension(300, 100));
	

		rightPanel.add((JPanel)algoPanel);
		
		add(leftPanel, java.awt.BorderLayout.WEST);
	        add(rightPanel, java.awt.BorderLayout.CENTER);
		
	}


	public void setCurrentAlgo(int id){
		keyList.setSelectedIndex(id);
	}




	public void connectAlgoManager(AlgoManager am){
		algoManager=am;
	}


	public void valueChanged(ListSelectionEvent e){
		int selectedAlgo;
		AlgoPanel selectedPanel;
		
		selectedAlgo=keyList.getSelectedIndex();
		selectedPanel=algoManager.getAlgo(selectedAlgo).getPanel();
		rightPanel.remove(0);
		rightPanel.add((JPanel)selectedPanel,0);
		rightPanel.validate();
		rightPanel.repaint();
		algoManager.setActiveAlgo(selectedAlgo);
	}	


}
